<?php
namespace logic\sys\power;
/**
 * 角色管理
 */
class Role{
    
    private $User;
    public function __construct(\logic\user\User $user){
        $this->User = $user;
    }
    
    /**
     * 查找一条记录
     */
    public function find($param){
       // if( !isset($param['plat']) ) $param['plat'] = app('passport')->plat;
        return  D('Role','sysPower')->find($param);
    }
    
    
    /**
     * 读取一个列表角色列表
     */
    public function getList($param){
        if( !isset($param['plat']) ) $param['plat'] = app('passport')->plat;
        return  D('Role','sysPower')->getList($param);
    }
    
    /**
     * 添加一个角色
     */
    public function add($data){
        $check = [
            'plat'      => ['check'=>'must','msg'=> '角色所属平台不能为空','reg'=>'int'],
            'role'      => ['check'=>'must','msg'=>'请填写角色名称'],
            'remark'    => '',
        ];        
        $save = pVerify($check,$data);  
        $save['type'] = 2;  
        return D('Role','sysPower')->add($save);        
    }
    
    /**
     * 编辑一个角色
     */
    public function edit($roleid,$data){
        $check = [
            'plat'      => '',
            'role'      => ['check'=>'must','msg'=>'请填写角色名称'],
            'remark'    => '',
        ];        
        $save = pVerify($check,$data);
        $RoLeMenuManage = new \logic\sys\power\RoleMenu($this->User);
        $checkpower = $RoLeMenuManage->getRolePowerList($roleid);
        if( $checkpower )  unset($save['plat']);
        return D('Role','sysPower')->edit($roleid,$save);        
    }
    
}